import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/item/card_item.dart';
import 'package:animal/item/shop_list_item.dart';
import 'package:animal/ui/goods/Controller/shop_info_controller.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/widgets/button/icon_text_button.dart';
import 'package:animal/widgets/image_widget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///店铺详情
class ShopInfoPage extends StatefulWidget {
  ShopInfoPage({Key? key}) : super(key: key);

  @override
  State<ShopInfoPage> createState() => _ShopInfoPageState();
}

class _ShopInfoPageState extends State<ShopInfoPage> with TickerProviderStateMixin {
  late ShopInfoController controller;
  late TabController tabController;

  List<Widget> pageList = [
    const Center(child: Text("页面一")),
    const Center(child: Text("页面二")),
    const Center(child: Text("页面三")),
  ];

  @override
  Widget build(BuildContext context) {
    controller = Get.put(ShopInfoController());
    return Scaffold(
        backgroundColor: KColorConstant.appBgColor,
        body: NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
              SliverOverlapAbsorber(
                handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                sliver: Obx(() => _buildSliverAppBar()),
              )
            ];
          },
          body: SingleChildScrollView(
            controller: controller.scrollController,
            child: Column(
              children: [
                Container(
                  margin: EdgeInsets.only(top: ScreenUtil().L(2)),
                  padding: EdgeInsets.only(top: ScreenUtil().L(100), bottom: ScreenUtil().L(30), left: ScreenUtil().L(20), right: ScreenUtil().L(20)),
                  color: Colors.blue,
                  child: Row(
                    children: [
                      ImageWidget(width: 70, height: 70, borderRadius: BorderRadius.circular(0), borderWidth: 3),
                      Container(width: ScreenUtil().L(10)),
                      Expanded(
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text("韩国重庆专卖店", style: KFontConstant.myTextStyle(size: 18, color: Colors.white)),
                            Container(height: ScreenUtil().L(10)),
                            Text("四川  成都", style: KFontConstant.myTextStyle(size: 15, color: Colors.white)),
                            Container(height: ScreenUtil().L(10)),
                            CardItem(text: "商家认证", imageWidth: ScreenUtil().l(20), textStyle: KFontConstant.myTextStyle(size: 13, color: Colors.white)),
                          ],
                        ),
                      ),
                      Container(
                          decoration: BoxDecoration(
                              border: Border.all(width: ScreenUtil().L(0.5), color: Colors.white), borderRadius: BorderRadius.circular(ScreenUtil().L(4))),
                          child: IconTextButton(
                            name: "联系商家",
                            style: KFontConstant.myTextStyle(size: 15, color: Colors.white),
                            iconWidget: const Icon(Icons.message, color: Colors.white),
                            direction: Direction.left,
                            widgetHeight: ScreenUtil().L(25),
                            widgetWidth: ScreenUtil().L(100),
                          ))
                    ],
                  ),
                ),
                Container(
                  color: Colors.white,
                  child: Column(
                    children: [
                      TabBar(
                          tabs: const [
                            Text("页面一"),
                            Text("页面二"),
                            Text("页面三"),
                          ],
                          controller: tabController,
                          unselectedLabelStyle: KFontConstant.myTextStyle(size: 20, color: Colors.black),
                          unselectedLabelColor: Colors.red,
                          labelColor: Colors.blueAccent,
                          onTap: (a){

                          },
                          labelStyle: KFontConstant.myTextStyle(size: 20, color: Colors.blue)),
                      ListView.builder(
                          itemCount: 7,
                          shrinkWrap: true,
                          physics: const NeverScrollableScrollPhysics(),
                          itemBuilder: (context, index) {
                            return ShopListItem();
                          }),
                    ],
                  ),
                )
              ],
            ),
          ),
        ));
  }

  ///上部分AppBar内容
  Widget _buildSliverAppBar() {
    return SliverAppBar(
      pinned: true,
      backgroundColor: controller.appBarColor.value,
      leading: GFIconButton(
        onPressed: () {},
        color: Colors.black26,
        type: controller.appBarColor.value == Colors.white ? GFButtonType.solid : GFButtonType.transparent,
        size: ScreenUtil().L(20),
        shape: GFIconButtonShape.circle,
        icon: const Icon(
          Icons.keyboard_return,
          color: Colors.white,
        ),
      ),
      centerTitle: true,
      title: Text("店铺详情",
          style: KFontConstant.myTextStyle(size: 17, bold: true, color: controller.appBarColor.value == Colors.transparent ? Colors.white : Colors.black)),
      elevation: 1,
    );
  }

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 3, vsync: this);
  }
}
